package com.qf.controller;

import com.qf.entity.Colorclass;
import com.qf.entity.Product;
import com.qf.service.ColorClassService;
import com.qf.service.ProductService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author chen
 * @version 1.0
 * @date 2019/10/24 18:21
 */
@Controller
public class ProductController {
    @Resource
    private ProductService productService;
    @Resource
    private ColorClassService colorClassService;

    @RequestMapping("/comment/getProducts")
    @ResponseBody
    public Map getProducts(@RequestParam(defaultValue = "1") Integer pageIndex){
        List<Product> productList = productService.getProducts(pageIndex);
        Map map = new HashMap();
        map.put("code", 1);
        map.put("msg", "success");
        map.put("productList", productList);
        return map;
    }

    @RequestMapping("/comment/getColorClass")
    @ResponseBody
    public Map getColorClass(Integer productId){
        Product product = productService.getProductByProductId(productId);
        List<Colorclass> list = colorClassService.getColorClassByProductId(product.getProductid());

        Map map = new HashMap();
        map.put("code", 1);
        map.put("msg", "success");
        map.put("product", product);
        map.put("colorClass", list);
        return map;
    }











}
